package com.leo.customer.utils

import com.alibaba.fastjson.JSON
import com.leo.customer.entity.pojo.User
import javax.servlet.http.HttpServletRequest

/**
 * 扩展HttpServletRequest方法
 * 直接获取attribute对应的对象数据
 */
fun <T> HttpServletRequest.getObjByKey(key: String, clazz: Class<T>): T = this.let {
    val attribute = it.getAttribute(key) as String
    JSON.parseObject(attribute, clazz)
}

/**
 * 在Request中获取User
 */
fun HttpServletRequest.getUser(): User = this.let {
    Utils.getUserFromRequest(it)
}
